package com.file;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileOutputStream;
import java.io.InputStream;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/6/22 18:38
 * @since JDK 1.8
 */
@RestController
@RequestMapping("filetest")
public class FileController {

    @RequestMapping("upload")
    public void fileToUpload(InputStream inputStream) throws Exception{
        if(inputStream!=null){
            String file="C:\\Users\\xiong\\Desktop\\123.txt";
            int index;
            byte[] bytes = new byte[1024];
            FileOutputStream downloadFile = new FileOutputStream(file);
            while ((index = inputStream.read(bytes)) != -1) {
                downloadFile.write(bytes, 0, index);
                downloadFile.flush();
            }
            inputStream.close();
            downloadFile.close();
        }
    }



}
